#region imported Namespaces
using System;
using System.Data;
using System.Data.SqlClient;

using BO = PHSRAG.Insight21.BusinessObjects;
using Utility = PHSRAG.Utility;
using ICachePolicy = PHSRAG.Insight21.Policy.ICachePolicy;
#endregion

namespace PHSRAG.Insight21.Personnel
{
	#region Class ExpiredFundAllocation
	/// <summary>
	/// The ExpiredFundAllocation class is the facade over the details
	/// for a single expired fund allocation data.
	/// </summary>
	public class ExpiredFundAllocation:BO.BusinessObject
	{
		#region Constants
		private const string ExpiredFundAllocationKey		= "ExpiredFundAllocation_20C8DFC6-39DF-4965-A36C-0BA6A1AE763E";
		//Constants to hold the column names
		private const string JobMapIdColumnName				= "EmployeeJobMapId";
		private const string FundNumberColumnName			= "FundNumber";
		private const string ProjectEndDateColumnName		= "ProjectEndDate";
		private const string EmployeeNameColumnName			= "EmployeeName";
		private const string EffectiveDateColumnName		= "AllocationStartDate";
		private const string ExpirationDateColumnName		= "AllocationEndDate";
		private const string HRDepartmentColumnName			= "HRDepartment";
		private const string SalaryAllocationColumnName		= "SalaryAllocated";
		private const string FeedSourceIndicatorColumnName	= "FeedSourceIndicator";
		#endregion

		#region Instance variables
		private DataRow allocationRow;
		#endregion

		#region Public Properties
		/// <summary>
		/// Get the EmployeeJobMapId of the employee
		/// It is a non nullable field.
		/// </summary>
		public int EmployeeJobMapID
		{
			get
			{
				return (int)allocationRow[JobMapIdColumnName];
			}
		}
		/// <summary>
		/// Get the fund number
		/// It is a non nullable field.
		/// </summary>
		public string FundNumber
		{
			get
			{
				return allocationRow[FundNumberColumnName].ToString();
			}
		}
		/// <summary>
		/// Get the project end date for the agreement related to the fund. 
		/// Return an empty string if no end date is assigned to the project.
		/// </summary>
		public string ProjectEndDate
		{
			get
			{
				object projectEndDate = allocationRow[ProjectEndDateColumnName];
				return (projectEndDate == DBNull.Value) ? 
					string.Empty : ((DateTime)projectEndDate).ToString("MM/dd/yyyy");
			}
		}
		/// <summary>
		/// Get the emplyee name (Last name,First name)
		/// It is a non nullable field.
		/// </summary>
		public string EmployeeName
		{
			get
			{
				return allocationRow[EmployeeNameColumnName].ToString();
			}
		}
		/// <summary>
		/// Get the fund effective date of the employee's salary.
		/// Return an empty string if no effective date is assigned to the salary.
		/// </summary>
		public string EffectiveDate
		{
			get
			{
				object effectiveDate = allocationRow[EffectiveDateColumnName];
				return (effectiveDate == DBNull.Value) ? 
					string.Empty : ((DateTime)effectiveDate).ToString("MM/dd/yyyy");
			}
		}
		/// <summary>
		/// Get the fund expiration date of the employee's salary.
		/// Return an empty string if no expiration date is assigned to the salary.
		/// </summary>
		public string ExpirationDate
		{
			get
			{
				object expirationDate = allocationRow[ExpirationDateColumnName];
				return (expirationDate == DBNull.Value) ? 
					string.Empty : ((DateTime)expirationDate).ToString("MM/dd/yyyy");
			}
		}
		/// <summary>
		/// Get the salary allocated for the employee
		/// Return 0 if no salary is allocated to the employee
		/// </summary>
		public decimal SalaryAllocated
		{
			get
			{
				object salaryAllocated = allocationRow[SalaryAllocationColumnName];
				return (salaryAllocated == DBNull.Value) ? 0 : (decimal)salaryAllocated;
			}
		}
		/// <summary>
		/// Get the hr department to which the employee belongs to
		/// Return an empty string if the employee has not HR Dept assocaited with him
		/// </summary>
		public string HRDepartment
		{
			get
			{
				object hrDept = allocationRow[HRDepartmentColumnName];
				return (hrDept == DBNull.Value) ? string.Empty : hrDept.ToString();
			}
		}
		/// <summary>
		/// Get the feed source indicator
		/// True if the feed is from PS,false otherwise
		/// </summary>
		public bool FeedSourceIndicator
		{
			get
			{
				return (bool)allocationRow[FeedSourceIndicatorColumnName];
			}
		}
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the base class with the specified cache policy, and save the DataRow in this instance.
		/// </summary>
		/// <param name="cachePolicy">Prevalent cache policy</param>
		/// <param name="dataRow">DataRow containing expired fund allocation data</param>
		public ExpiredFundAllocation(ICachePolicy cachePolicy, DataRow dataRow) : base(cachePolicy)
		{
			allocationRow = dataRow;
		}		
		#endregion

		#region BusinessObject Methods
		/// <summary>
		/// Cache the ExpiredFundAllocation instance using the prevalent cache policy
		/// </summary>
		public override void Cache()
		{
			CachePolicy.Cache(ExpiredFundAllocationKey,this);
		}
		/// <summary>
		/// Remove the ExpiredFundAllocation instance from the cache using the prevalent cache policy
		/// </summary>
		public override void UnCache()
		{
			CachePolicy.UnCache(ExpiredFundAllocationKey);
		}
		/// <summary>
		/// This method is not used and only exists to satisfy interface requirements.
		/// </summary>
		public override void Load(string connectionString, params object[] args)
		{
			throw new Exception("ExpiredFundAllocation cannot be directly loaded.");
		}
		#endregion
	}
	#endregion
}